﻿#include <iostream>
#include "Head/Stuck.h"

Stuck::Stuck()
{
    arr = 0;
    for (int times; times < arrMax; times++)
        memory_[times]= {0};
};

bool Stuck::add(const Item & num)
{
    if (arr < arrMax)
    {

        memory_[arr++] = num;
        return true;
    }
    else
        return false;
};

bool Stuck::remove(Item & num)
{
    if (arr > 0)
    {
        num = memory_[--arr];
        return true;
    }
    else
        return false;
};
void Stuck::ctrl(void (*func) (Item &, double), double times)
{
    for (int time = 0; time < arrMax; time++)
    {
        func(memory_[time], times);
    };
};

void Stuck::show() const
{
    for (int times = 0; times < arr; times++)
        std::cout << "栈层 " << times << " 内容：" << memory_[times] << std::endl;
};

bool Stuck::full() const
{
    return arr == arrMax;
};

bool Stuck::empty() const
{
    return arr == 0;
};

void mul (Item & num, double times)
{
    num *= times;
};

void div (Item & num, double times)
{
    num /= times;
};

Item Stuck::cin(Item Min, Item Max)
{
    using std::cin;
    int i_temp = 0;
    char c_temp;
    while ((!(cin >> i_temp)) || (!(i_temp >= Min && i_temp <= Max)))
    {
        cin.clear();
        while (cin.get() != '\n')
            continue;
        std::cout << "出现异常 - 请输入一个指定范围内的整数。" << "\t( " << Min << " ~ " << Max << " )" << std::endl;
    };
    return i_temp;
};
